<div class="pageContent" layoutH="28">
	<div id='mainResUseStatus' style='width:600px; height:400px; margin:10px 20px; float:left;'>
		<div align='center'>
			<font style='color:#000; font-size:17px;font-weight:bold; text-align:center;'>监控系统使用概况</font>	
		</div>
		<div id='mainResMachine' class='mainPageRes'></div>
		<div id='mainWarnDealing' class='mainPageRes'></div>
		<div id='mainWarnUnDeal' class='mainPageRes'></div>
		<div id='mainResApp' class='mainPageRes'></div>
		<div id='mainResLogs' class='mainPageRes'></div>
		<div id='mainResDisk' class='mainPageRes'></div>
	</div>
	<div id='mainChartAttr' class='mainPageChart'></div>
	<div id='mainChartDisk' class='mainPageChart'></div>
</div>

<div class="pageHeader" style='padding:0px 0px; height:40px;'>
    <div class="searchBar">
        <ul class="searchContent accountInfo">
			<li style='margin-left:10px; float:left; font-size:14px; font-weight:400; color:red; width:600px; overflow:hidden;'> 
				<?cs if:config.notify_daemon ?>
				<span id='dcNotifyMsg' style="font-weight:400; font-size:14px; color:red;"></span>
				<?cs else ?>
				<marquee onMouseOut='start();' onMouseOver='stop();' scrollamount="2" align='middle' id='dcNotifyMsg' loop=-1 behavior="alternate" style='text-decoration:underline;'></marquee>
				<?cs /if ?>
			</li>
		</ul>
		<div class='subBar' style='top:5px;'>
			<ul>
				<li><button type='button' class='buttonActive' id="dc_btn_hidden_tip" style='display:none'>不再显示当前消息</button></li>
				<li><button type="button" class='buttonActive' id="dc_btn_refresh"><i class='icon-refresh icon-large'></i>刷新</button></li>
			</ul>
        </div>
    </div>
</div>


<script language="javascript" type="text/javascript">
var g_dcAppInfoAddr = 'local'; //'<?cs var:config.app_info_addr ?>';
var g_dcChartDiskUse = null;
var g_dcChartAttrUse = null;

var g_dcChartMinWidth = 420;
var g_dcMainInfoWidthFix = 600; // 等于 id mainResUseStatus 的 width
var g_dcMainChartWidth = 420;
var g_dcMainFirstChartWidth = 420;
var g_dcMainFirstChartCount = 0;
var g_dcLastContentW = 0;

// navtab 切回到 - '我的主页'
function dcOnMainPage(idx)
{
	if(typeof idx == 'undefined')
		$('#navTab').find('.main').trigger('click');
	dcMainPageSetChartSize();
	dcMainPageRedrawChart();
}

function dcMainPageRedrawChart()
{
	if(g_dcChartAttrUse != null) {
		if(g_dcMainFirstChartCount > 0) {
			$('#mainChartAttr').css('width', g_dcMainFirstChartWidth);
			g_dcChartAttrUse.resize();
		}
		else {
			$('#mainChartAttr').css('width', g_dcMainChartWidth);
			g_dcChartAttrUse.resize();
		}

		if(g_dcMainFirstChartCount > 1) {
			$('#mainChartDisk').css('width', g_dcMainFirstChartWidth);
			g_dcChartDiskUse.resize();
		}
		else {
			$('#mainChartDisk').css('width', g_dcMainChartWidth);
			g_dcChartDiskUse.resize();
		}
	}
}

function dcMainPageSetChartSize()
{
	// 25 -- 预留给滚动条
	var iContentW = $(window).width() - (DWZ.ui.sbar ? $("#sidebar").width() + 10 : 34) - 5 - 25;
	if(g_dcLastContentW == iContentW)
		return;
	g_dcLastContentW = iContentW;

	if(iContentW <= g_dcChartMinWidth+20+20) {
		g_dcMainChartWidth = g_dcChartMinWidth;
		g_dcMainFirstChartWidth = g_dcChartMinWidth;
	}
	else {
		var xWidth = g_dcChartMinWidth+20+20;
		var xLeft = iContentW % xWidth;
		var xCount = dmtMathtrunc(iContentW/xWidth);
		var xBlank = dmtMathtrunc(xLeft/xCount);
		g_dcMainChartWidth = g_dcChartMinWidth+xBlank;

		iContentW -= g_dcMainInfoWidthFix+20+20;
		xLeft = iContentW % xWidth;
		xCount = dmtMathtrunc(iContentW/xWidth);
		if(xCount > 0) {
			xBlank = dmtMathtrunc(xLeft/xCount);
			g_dcMainFirstChartWidth = g_dcChartMinWidth+xBlank;
			g_dcMainFirstChartCount = xCount;
		}
		else
			g_dcMainFirstChartCount = 0;
	}
}

function dcSetAttrInfoEChart(result)
{
	var op = {
		title: {
			x: 'center',
			text:'自定义监控点使用分布'
		},
		tooltip: {
			trigger:'item',
			confine:true,
			formatter: '{b} <br /> {c} ({d}%)'
		},
		grid: {
		},
		series: [
			{
				type:'pie',
				name:'自定义监控点',
				radius:'75%',
				center:['50%', '54%'],
				data:[],
				label: { 
					show: true,
	        		normal: {
            	        show: false,
            	        position: 'inside'
            	    },
            	    emphasis: {
            	        show: false,
            	    }
            	},
				itemStyle: {
					emphasis: {
						shadowBlur: 10,
						shadowOffsetX: 0,
						shadowColor: 'rgba(0, 0, 0, 0.5)'
					}
				}
			}
		]
	};

	op.series[0].data = result.attr_info;
	op.series[0].label = { show: true, formatter: '{b}：{d}%' };
	if(g_dcMainFirstChartCount > 0)
		$('#mainChartAttr').css('width', g_dcMainFirstChartWidth);
	else
		$('#mainChartAttr').css('width', g_dcMainChartWidth);

	if(g_dcChartAttrUse != null)
		g_dcChartAttrUse.dispose();
	g_dcChartAttrUse = echarts.init(document.getElementById('mainChartAttr'));
	g_dcChartAttrUse.setOption(op);
}

function dcSetAppDiskInfoEChart(result)
{
	var op = {
		title: {
			x: 'center',
			text:'日志系统磁盘空间使用分布'
		},
		tooltip: {
			trigger:'item',
			formatter: function (params) {
				var sstr = params.data.name + '<br />';
				sstr += dmtGetHumanReadDigitByKB(params.data.value) + ', ';
				sstr += '('+ params.percent + '%)';
				return sstr;
			}
		},
		grid: {
		},
		series: [
			{
				type:'pie',
				name:'应用名称',
				radius:'75%',
				center:['50%', '54%'],
				data:[],
				label: { 
					show: true,
	        		normal: {
            	        show: true,
            	        position: 'inside'
            	    },
            	    emphasis: {
            	        show: false,
            	    }
            	},
				itemStyle: {
					emphasis: {
						shadowBlur: 10,
						shadowOffsetX: 0,
						shadowColor: 'rgba(0, 0, 0, 0.5)'
					}
				}
			}
		]
	};

	op.series[0].data = result.app_disk_info;
	op.series[0].label = { show: true, formatter: '{b}：{d}%' };
	if(g_dcMainFirstChartCount > 1)
		$('#mainChartDisk').css('width', g_dcMainFirstChartWidth);
	else
		$('#mainChartDisk').css('width', g_dcMainChartWidth);

	if(g_dcChartDiskUse != null)
		g_dcChartDiskUse.dispose();
	g_dcChartDiskUse = echarts.init(document.getElementById('mainChartDisk'));
	g_dcChartDiskUse.setOption(op);
}

function dcSetResourceUseEChart(res)
{
	var op = null;

	var dcChartResMachine = echarts.init(document.getElementById('mainResMachine'));
	op = dmtGetUsePerPieOption({
			c_text:'监控服务器\n', 
			c_subtext:res.machine_count, 
			c_val:100, 
			c_name:'mainResMachine', 
			c_colors:['#1d54f7', '#00cefc', '#68eaf9', '#367bec'],
			c_sublink:'#'
		});
	dcChartResMachine.setOption(op);
	dcChartResMachine.on('click', function(para) { 
			navTab.openTab('dmt_machine', g_siteInfo.cgi_path + 'mt_slog_machine?action=list',
			    {title:'上报机器管理', titleHtml:"<i class='icon icon-desktop'></i>上报机器管理", fresh:true});
		});

	var dcChartWarnUnDeal= echarts.init(document.getElementById('mainWarnUnDeal'));
	op = dmtGetUsePerPieOption({
			c_text:'未处理告警\n', 
			c_subtext:''+res.warn_undeals, 
			c_val:100, 
			c_name:'mainWarnUnDeal', 
			c_colors:['#d48265', '#ff0000', '#f00', '#d48265', 'red'],
			c_sublink:'#'
		});
	dcChartWarnUnDeal.setOption(op);
	dcChartWarnUnDeal.on('click', function(para) {
			navTab.openTab('dmt_warn_list', 
				g_siteInfo.cgi_path + 'mt_slog_showview?action=search_warn_list&dwl_deal_status_sel=0',
			    {title:'监控点告警列表', titleHtml:"<i class='icon icon-screenshot'></i>监控点告警列表", fresh:true});
		});

	var dcChartWarnDealing = echarts.init(document.getElementById('mainWarnDealing'));
	op = dmtGetUsePerPieOption({
			c_text:'处理中告警\n', 
			c_subtext:''+res.warn_dealings, 
			c_val:100, 
			c_name:'mainWarnDealing', 
			c_sublink:'#',
			c_colors:['#ca8622', '#d48265', '#d48265', '#ca8622', '#d48265']
		});
	dcChartWarnDealing.setOption(op);
	dcChartWarnDealing.on('click', function(para) {
			navTab.openTab('dmt_warn_list', 
				g_siteInfo.cgi_path + 'mt_slog_showview?action=search_warn_list&dwl_deal_status_sel=1',
			    {title:'监控点告警列表', titleHtml:"<i class='icon icon-screenshot'></i>监控点告警列表", fresh:true});
		});

	var dcChartResApp = echarts.init(document.getElementById('mainResApp'));
	op = dmtGetUsePerPieOption({
			c_text:'应用数：'+res.app_count+'\n', 
			c_subtext:'模块数：'+res.module_count, 
			c_val:100, 
			c_name:'mainResApp', 
			c_colors:['#15d9b2', '#06de9b', '#68eaf9', '#367bec'], 
			c_sublink:'#',
			c_items:2
		});
	dcChartResApp.setOption(op);
	dcChartResApp.on('click', function(para) {
			navTab.openTab('dmt_list_app', 
				g_siteInfo.cgi_path + 'mt_slog?action=list_app',
			    {title:'应该管理', titleHtml:"<i class='icon icon-th-large'></i>应用管理", fresh:true});
		});

	var dcChartLogs = echarts.init(document.getElementById('mainResLogs'));
	op = dmtGetUsePerPieOption({
			c_text:'日志记录数\n', 
			c_subtext:res.log_records, 
			c_val:100, 
			c_sublink:'#',
			c_name:'mainResModule', 
			c_colors:['#1d54f7', '#00cefc', '#68eaf9', '#367bec']
		});
	dcChartLogs.setOption(op);
	dcChartLogs.on('click', function(para) {
			navTab.openTab('dmt_realtime_log', 
				g_siteInfo.cgi_path + 'mt_slog?action=show_realtime_log',
			    {title:'实时日志查看', titleHtml:"<i class='icon icon-cloud-upload'></i>实时日志查看", fresh:true});
		});

	var logSpace = '';
	if(res.log_space_kb > 0)
		logSpace = dmtGetHumanReadDigitByKB(res.log_space_kb);
	else 
		logSpace = result.log_space_b+' B';
	var dcChartResDisk = echarts.init(document.getElementById('mainResDisk'));
	op = dmtGetUsePerPieOption({
			c_text:'已使用磁盘空间\n', 
			c_subtext:logSpace, 
			c_val:100, 
			c_name:'mainResDisk', 
			c_sublink:'#',
			c_colors:['#749f83', '#61a0a8', '#61a0a8', '#749f83']
		});
	dcChartResDisk.setOption(op);
	dcChartResDisk.on('click', function(para) {
			navTab.openTab('dmt_log_files', 
				g_siteInfo.cgi_path + 'mt_slog?action=log_files',
			    {title:'日志文件列表', titleHtml:"<i class='icon icon-cloud-download'></i>日志文件列表", fresh:true});
		});
}

function dcInitMainPage()
{
	$('#dc_btn_refresh').click(dcRefreshStatInfo);

	<?cs if:config.notify_daemon ?>
	$('#dcNotifyMsg').text("温馨提示：当前版本为演示版，某些操作已被禁止");
	<?cs else ?>
	$('#dc_btn_hidden_tip').click(function() {
		$('#dcNotifyMsg').css('display', 'none');
		window.localStorage.setItem('cur_hide_tips_id', $('#dcNotifyMsg').data('tips_news_id'));
		$('#dc_btn_hidden_tip').css('display', 'none');
	});

	// 尝试从云版本中拉取最新的开源版本信息或者相关的技术文章，如果拉取到则在主页展示提示信息
	// 用户如不需要可以自行删除该部分代码，建议您保留以便获取到最新的项目动态
	var requrl = '<?cs var:config.xrkmonitor_url ?>/cgi-bin/mt_slog_open';
	var reqdata = new Object();
	reqdata.action = 'open_get_news';
	reqdata.rhost = location.host;
	reqdata.rurl = location.href;
	$.ajax({
		type:'post',
		url: requrl,
		data: reqdata,
		global: false,
		dataType: 'json',
		success: function(js) {
			var hId = window.localStorage.getItem('cur_hide_tips_id');
			if(js.ret == 0 && hId != js.news_id) {
				$('#dcNotifyMsg').text(js.news_text);
				if(typeof js.news_title != 'undefined')
					$('#dcNotifyMsg').attr('title', js.news_title);
				var nlink = '<a style="font-size:16px; font-weight:500; cursor:pointer; color:red;"';
				nlink += ' target="_blank" href="' + js.news_url + '"></a>';
				$('#dcNotifyMsg').wrap(nlink);
				$('#dcNotifyMsg').data('tips_news_id', js.news_id);
				$('#dc_btn_hidden_tip').css('display', 'block');
				$('.center').css('cursor', 'pointer');
			}
		}
	});
	<?cs /if ?>
}

function dcSetStatInfo(result)
{
	if(dmtFirstDealAjaxResponse(result))
		return;
	dcSetResourceUseEChart(result);
	dcSetAttrInfoEChart(result);
	dcSetAppDiskInfoEChart(result);
}

function dcRefreshStatInfo()
{
	var requrl = '';
	var para = new Object();
	para.action = 'refresh_main_info';

	if(g_dcAppInfoAddr == 'local') {
		requrl = g_siteInfo.cgi_path + "mt_slog?";
	}
	else {
		para.ex_flogin_user = $.cookie("flogin_user");
		para.ex_flogin_md5 = $.cookie("flogin_md5");
		para.ex_flogin_type = $.cookie("flogin_type");
		para.ex_flogin_uid = $.cookie("flogin_uid");
		para.ex_flogin_index = $.cookie("flogin_index");
		requrl = 'http://'+g_dcAppInfoAddr+g_siteInfo.cgi_path + "mt_slog?";
	}

	$.ajax({
		type: "POST",
		url: requrl,
		data: para,
		success: dcSetStatInfo,
		dataType: 'json', 
		global: false,
		error: function() {
		    alertMsg.warn("脚本请求出错");
		}  
	});
}

</script>


